/* eslint-disable no-unused-vars */
function f(count) {
  const cached = {};

  function recurse(n) {
    if (n === 0) return 0;
    if (cached[n]) return cached[n];

    let min = Infinity;
    if (n >= 1) min = Math.min(min, recurse(n - 1) + 1);

    if (n >= 5) min = Math.min(min, recurse(n - 5) + 1);

    if (n >= 11) min = Math.min(min, recurse(n - 11) + 1);

    cached[n] = min;
    return min;
  }

  return recurse(count);
}

console.log(f(1640));

function coinChange(coins, amount) {
  const dp = [0];

  for (let i = 1; i <= amount; i++) {
    dp[i] = Math.min(...coins.map((coin) => dp[i - coin] ?? Infinity)) + 1;
  }

  return dp[amount] === Infinity ? -1 : dp[amount];
}

console.log(coinChange([1, 5, 11], 1640));
